<template>
  <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="问题标题" prop="deviceName">
          <el-input v-model="deviceName" placeholder="请输入问题标题"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="studentList">
        <el-table-column label="问题标题" align="center" prop="deviceName" />
        <el-table-column label="问题描述" align="center" prop="deviceName" />
        <el-table-column label="反馈人" align="center" prop="deviceName" />
        <el-table-column label="反馈时间" align="center" prop="deviceTime">{{ '2023-11-12'}}</el-table-column>
        <el-table-column label="是否解决" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.yd_yesorno_type" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >解决</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >未解决</el-button>
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >管理</el-button> -->
<!--            <el-button-->
<!--              size="mini"-->
<!--              type="text"-->
<!--              icon="el-icon-delete"-->
<!--              @click="handleDelete(scope.row)"-->
<!--              v-hasPermi="['base:student:remove']"-->
<!--            >删除</el-button>-->
            <!--          <el-button-->
            <!--            size="mini"-->
            <!--            type="text"-->
            <!--            icon="el-icon-view"-->
            <!--            @click="handleDelete(scope.row)"-->
            <!--            v-hasPermi="['base:student:remove']"-->
            <!--          >查看</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    <!-- 添加或修改学生对话框 -->
    <el-dialog  :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-tabs type="card" >
          <el-form-item label="年级" prop="userName">
            <div>{{form.userName}}</div>
          </el-form-item>
          <el-form-item label="班级" prop="className">
            <div>{{form.className}}</div>
          </el-form-item>
          <el-form-item label="问题标题" prop="deviceName">
            <div>{{form.deviceName}}</div>
          </el-form-item>
          <el-form-item label="问题描述" prop="deviceType">
            <div>{{form.deviceType}}</div>
          </el-form-item>
          <el-form-item label="是否解决" prop="status">
            <el-select v-model="form.status" placeholder="请选择设备状态" >
              <el-option
                v-for="dict in dict.type.yd_yesorno_type"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
                size="small">
              </el-option>
            </el-select>
          </el-form-item>


        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>


import { addYdevicerecord, listYdevice, updateYdevicerecord } from '@/api/base/device'

export default {
  name: "gzt",
  dicts: ['yd_yesorno_type'],
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 显示搜索条件
      showSearch: true,
      // 学生表格数据
      studentList: [],
      total:0,
      // 遮罩层
      loading: true,
      rules:{

      },
      form:{},
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title: "",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学生列表 */
    async getList() {
      try {
        this.loading = true;
        const data=await listYdevice(this.queryParams);
        this.studentList = data.rows;
        this.total = data.total;
        this.loading = false;
      }catch (e) {
        console.log(e)
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.form = Object.assign({}, this.form, row)
      this.open = true;
      this.title = "修改设备管理";
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deviceId: null,
        deviceName: null,
        userId: null,
        userName: null,
        classId: null,
        roomName: null,
        deviceType: null,
        schoolCode: null,
        status: null,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateYdevicerecord(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYdevicerecord(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
